import { Component, OnInit } from '@angular/core';
import { NgModule} from '@angular/core';
import {FormControl, Validators} from '@angular/forms';
import {LoginsevService} from '../service/loginsev.service';
/*import {RouterModule, Routes} from '@angular/router'*/
import { DialogService, DeleteManaConfirm } from '../service/dialog.service';
import { ApiServiceService } from '../api.service';

import {RouterModule, Router} from '@angular/router';

const USERNAME_REGEX = /^[a-zA-Z][a-zA-Z0-9]*$/;
const PWD_REGEX = /^[a-zA-Z][a-zA-Z0-9]*$/;


/*export class User {
 username: string;
 password: string;
}*/

@Component({
  selector: 'app-login',
  templateUrl: './login1.component.html',
  styleUrls: ['./login1.component.css'],

/*  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],*/
  providers: [ApiServiceService]
/*  providers: [LoginsevService]*/
})
export class LoginComponent implements OnInit {

  username: string;
  password: string;

  logingFormControl = new FormControl('', [
    Validators.required,
    Validators.pattern(USERNAME_REGEX)
  ]);


  constructor(
    private  router: Router ,
/*  private  loginsevservice: LoginsevService,*/
    private dialogService: DialogService,
    private apiService: ApiServiceService
  ) { }

  ngOnInit() {

  }

  loginsystem(): void {
    this.router.navigate(['']);
    if(this.username == 'admin' && this.password == '1'){
      sessionStorage.uid = this.username;
      sessionStorage.upwd = this.password;
    }
    
    // this.apiService.logindata(this.username , this.password).subscribe(res=> {
    //   // this.router.navigate(['moduleList']);
    //   console.log(res);
    //   if (res.login =="success"){
    //     sessionStorage.uid = res.uid;
    //     sessionStorage.upwd = res.upwd;
    //     sessionStorage.ulevel = res.ulevel;
    //     sessionStorage.upriority = res.upriority;
    //     sessionStorage.product = res.product;
    //     sessionStorage.logourl = res.logo_url;
    //     sessionStorage.themeColor = res.theme_color;
    //     sessionStorage.finishNew = res.finish_new;
    //     sessionStorage.version = res.version;
    //     this.router.navigate(['']);
    //   }else{
    //     console.log("helloword");
    //   this.dialogService.openSnackBar("密码或用户名错误请重试",'');
    //   }
    // });

  }



  clearlogin(): void {
    console.log('清空登录数据')
   this.username = '';
   this.password = '';
   this.dialogService.openSnackBar('清空文本框内容成功','')

  }

}
